﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace LabMS.Web.BaseData
{
    public partial class EditStudentPrew : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            strPagePrivilege.Add("XSSJ");
            strPageUserType.Add("mana");
            strPageUserType.Add("student");
            if (!IsPostBack)
            {
                if (Request.QueryString["ID"] == null)
                {
                    Common.JShelper.JSAlert(this.Page, "", "你无权查看本页！");
                }
                else
                {
                    int ID =int.Parse(Request.QueryString["ID"].ToString());
                    InitDDl();
                    InitBind(ID);
                    textboxMajor.Attributes.Add("readOnly","true");
                    textboxClass.Attributes.Add("readOnly", "true");
                    tbRXLY.Attributes.Add("readOnly", "true");
                    tbSum.Attributes.Add("readOnly", "true");
                    textboxCode.Attributes.Add("readOnly", "true");
                    textboxName.Attributes.Add("readOnly", "true");
                }
            }
        }
        protected void InitDDl()
        {
            //性别
            ExtendBLL.Dictionary BD = new ExtendBLL.Dictionary();
            ddlSex.DataSource = BD.GetItemListByDClass("201");
            ddlSex.DataValueField = "Code";
            ddlSex.DataTextField = "Name";
            ddlSex.DataBind();
            //年级
            ExtendBLL.SysSetting ES = new ExtendBLL.SysSetting();
            int Year = ES.GetCurrentSetting().CurrentYear;
            int S = int.Parse(ES.GetCurrentSetting().CurrentSemester.Value.ToString());
            ddlLJ.DataSource = Common.GradeHelper.GetCurrentGrade(Year, S, false);
            ddlLJ.DataBind();
        }

        protected void InitBind(int ID)
        {
            LabMS.BLL.Student BStudent = new LabMS.BLL.Student();
            List<LabMS.Model.Student> list = new List<LabMS.Model.Student>();
            list = BStudent.GetModelList("ID="+ID);
            textboxCode.Text = list[0].Student_Code;
            textboxName.Text = list[0].Student_Name;
            ddlSex.SelectedValue = list[0].Student_Sex;//性别
            ddlLJ.SelectedValue = list[0].Student_Grade;//年级

            ExtendBLL.Class EClass = new ExtendBLL.Class();
            if (list[0].Student_Pro!= null&&!string.IsNullOrEmpty(list[0].Student_Pro.Value.ToString()))
            {
                textboxMajor.Text = EClass.ProessionalNameByID(int.Parse(list[0].Student_Pro.Value.ToString()));//专业
            }
            if (list[0].ClassID!=null&&!string.IsNullOrEmpty(list[0].ClassID.Value.ToString()))
            {
                textboxClass.Text = EClass.GetClassNameByClassID(int.Parse(list[0].ClassID.Value.ToString()));//班级
            }
            if (list[0].Student_EntryDate != null)
            {
                tbRXLY.Text = list[0].Student_EntryDate.Value.ToShortDateString();
            }
            tbSum.Text = list[0].Student_Summary;
            //if (!string.IsNullOrEmpty(list[0].Student_Photo.ToString()))
            //{
            //    imgStudent.ImageUrl = list[0].Student_Photo.ToString();
            //}
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            Response.Redirect("EditStudentInfo.aspx?ID=" + int.Parse(Request.QueryString["ID"].ToString()));
        }
    }
}
